Easy2Siksha
Think of a classroom with 10 chairs in a row. Each chair has a number from 0 to 9. Students
(data) can sit on these chairs. If a student is sitting on chair 5, you can directly go to that
position and talk to them. This direct access is a special feature of arrays.
Key Features of Arrays:
1. Fixed Size – Once declared, the size cannot be changed.
2. Same Data Type – All elements must be of the same type (int, float, char, etc.).
3. Indexed Access – You can access any element directly using its index.
4. Efficient for Searching – Especially if sorted, arrays are great for search algorithms
like Binary Search.
Types of Arrays:
1. One-Dimensional Array: A single row of elements.
Example: int marks[5] = {90, 85, 88, 92, 75};
2. Two-Dimensional Array (Matrix): Like a grid or table with rows and columns.
Example:
int matrix[2][3] = { {1,2,3}, {4,5,6} };
3. Multi-Dimensional Arrays: Arrays with more than two dimensions. Rare in practice
but useful in scientific computations.
Operations on Arrays:
• Traversal – Accessing each element one by one.
• Insertion – Adding an element (may require shifting other elements).
• Deletion – Removing an element (again may require shifting).
• Searching – Finding the position of an element.
• Updating – Changing the value of an element.
Real-World Example:
Suppose you are creating a result app for students. You can use an array to store marks:
int marks[5] = {45, 67, 89, 78, 90};
To calculate total marks, you simply loop through this array.
Limitations of Arrays:
1. Fixed Size – Cannot change the size once created.
2. Insertion/Deletion is Costly – Requires shifting elements.
3. Same Data Type Only – Cannot store mixed data types.